﻿Imports System.Data.SqlClient

Public Class Employe

    Public Id As Integer
    Public Nom As String
    Public Prenom As String
    Public Nom_a As String
    Public Prenom_a As String
    Public Date_naiss As Date
    Public Adress As String
    Public Date_emploi As Date
    Public Situation_social As String
    Public occupation As String
    Public Ville As String
    Public salaire As String
    Public email As String
    Public photo() As Byte
    Public Remarque As String
    Public Actif As String
    Public cin As String


    'Les constructeur -------------------------------
    Sub New(ByVal Id As Integer, ByVal Nom As String, ByVal Prenom As String, ByVal Nom_a As String, ByVal Prenom_a As String, ByVal Date_naiss As Date, ByVal Adress As String, ByVal Date_emploi As Date, ByVal Situation_social As String, ByVal occupation As String, ByVal Ville As String, ByVal salaire As String, ByVal email As String, ByVal photo() As Byte, ByVal Remarque As String, ByVal Actif As String, ByVal cin As String)
        Me.Id = Id
        Me.Nom = Nom
        Me.Prenom = Prenom
        Me.Nom_a = Nom_a
        Me.Prenom_a = Prenom_a
        Me.Date_naiss = Date_naiss
        Me.Adress = Adress
        Me.Date_emploi = Date_emploi
        Me.Situation_social = Situation_social
        Me.occupation = occupation
        Me.Ville = Ville
        If salaire <> "" Then
            Me.salaire = CType(salaire, Double)
        Else
            Me.salaire = 0
        End If
        Me.photo = photo
        Me.Remarque = Remarque
        Me.Actif = Actif
        Me.cin = cin
        Me.email = email
    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.Nom_a = enregistrement.Item(1)
        Me.Prenom_a = enregistrement.Item(2)
        Me.Nom = enregistrement.Item(3)
        Me.Prenom = enregistrement.Item(4)
        Me.cin = enregistrement.Item(5)
        Me.Date_naiss = enregistrement.Item(6)
        Me.Adress = enregistrement.Item(7)
        Me.Date_emploi = enregistrement.Item(8)
        Me.Situation_social = enregistrement.Item(9)
        Me.occupation = enregistrement.Item(10)
        Me.Ville = enregistrement.Item(11)
        Me.salaire = enregistrement.Item(12)
        Me.email = enregistrement.Item(13)
        Me.photo = enregistrement.Item(14)
        Me.Actif = enregistrement.Item(15)
        Me.Remarque = enregistrement.Item(16)
    End Sub

    Sub New()

    End Sub

    'les listes ---------------------------------

    Public list_phone As New ArrayList






    'les fonctions ---------------------------

    Public Sub remplir_List_list_phone()

        Partager.close()
        Me.list_phone.Clear()
        Partager.ad = New SqlDataAdapter("select id,Num,Type from phone where id_Employes=" & Me.Id, Partager.conPhone)
        Partager.ds = New DataSet
        Partager.ad.Fill(Partager.ds, "phone")
        For Each f As DataRow In Partager.ds.Tables(0).Rows
            If f("Num") Is DBNull.Value Then
                f("Num") = ""
            End If
            Dim khab As New Phone(f("id"), f("Num"), f("Type"))
            Me.list_phone.Add(khab)

        Next
        'Partager.Close()
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer, ByVal type As String)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where Type ='" & Type & "' and Id_Employes=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Employes) values (@Num,@Type,@Id_Employes)", Partager.con)

        cmd.Parameters.Add("@Id_Employes", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub modifier_List_phone(ByVal idd As Integer, ByVal ph As Phone)



        Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()

    End Sub

End Class
